<?php

// init common settings
error_reporting(E_ALL | E_STRICT);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/Sofia');


// init include path
define('SITE_PATH', realpath(dirname(__FILE__) . '/../'));

set_include_path(
    SITE_PATH . '/library' . PATH_SEPARATOR .
    SITE_PATH . '/application/models'
);


// init autoload
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();


// init config
$config = new Zend_Config_Ini(SITE_PATH . '/config/config.ini', 'default');
Zend_Registry::set('config', $config);


// init db
$db = Zend_Db::factory($config->db);
$db->query('SET NAMES "utf8"');
Zend_Registry::set('db', $db);
Zend_Db_Table_Abstract::setDefaultAdapter($db);


// init session
/*$session = new Zend_Session_Namespace();
Zend_Registry::set('session', $session);
var_dump($session->user);*/
//var_dump(Zend_Auth::getInstance()->getIdentity());


// init controller
$front = Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
$front->addModuleDirectory(SITE_PATH . '/application/modules');
$front->returnResponse(true);
$front->setBaseUrl($config->www->baseurl);


// set utf-8
$view = new Zend_View(array('encoding'=>'UTF-8'));
$view->doctype('XHTML11');
$viewRendered = new Zend_Controller_Action_Helper_ViewRenderer($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRendered);
$view->menuItems = array_reverse(array( // wtf?!?
    array('url' => '/cars/', 'title' => 'Автомобили'),
    array('url' => '/makes/', 'title' => 'Марки'),
    array('url' => '/features/', 'title' => 'Особености'),
    array('url' => '/colors/', 'title' => 'Цветове'),
    array('url' => '/fuels/', 'title' => 'Двигатели'),
    array('url' => '/styles/', 'title' => 'Категории'),
    array('url' => '/transmissions/', 'title' => 'Скоростни кутии'),
   //array('url' => '/user/logout/', 'title' => 'Изход'),
));


// init layout
Zend_Layout::startMvc(array(
    'layoutPath' => SITE_PATH . '/application/layouts',
    'layout' => 'main'
));


// run
$response = $front->dispatch();
$response->sendResponse();
